<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>体检预约系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: "Microsoft YaHei", sans-serif;
        }
        
        body {
            background-color: #f5f5f5;
            color: #333;
            line-height: 1.6;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        
        header {
            background-color: #1e88e5;
            color: white;
            padding: 15px 0;
            text-align: center;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        
        h1 {
            font-size: 24px;
        }
        
        .appointment-form {
            background-color: white;
            padding: 30px;
            border-radius: 5px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
        }
        
        input[type="text"],
        input[type="tel"],
        input[type="date"],
        input[type="time"],
        select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
        }
        
        .form-row {
            display: flex;
            gap: 20px;
        }
        
        .form-row .form-group {
            flex: 1;
        }
        
        .package-options {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            margin-top: 10px;
        }
        
        .package-option {
            flex: 1 0 calc(33.333% - 15px);
            min-width: 200px;
        }
        
        .package-card {
            border: 1px solid #ddd;
            border-radius: 5px;
            padding: 15px;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        
        .package-card:hover {
            border-color: #1e88e5;
            box-shadow: 0 2px 8px rgba(30, 136, 229, 0.2);
        }
        
        .package-card.selected {
            border-color: #1e88e5;
            background-color: #e3f2fd;
        }
        
        .package-card h3 {
            color: #1e88e5;
            margin-bottom: 10px;
        }
        
        .package-card .price {
            font-weight: bold;
            color: #e53935;
            margin: 10px 0;
        }
        
        .package-card .description {
            font-size: 14px;
            color: #666;
        }
        
        .submit-btn {
            background-color: #1e88e5;
            color: white;
            border: none;
            padding: 12px 20px;
            font-size: 16px;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
            transition: background-color 0.3s;
        }
        
        .submit-btn:hover {
            background-color: #1565c0;
        }
        
        .success-message {
            display: none;
            background-color: #e8f5e9;
            color: #2e7d32;
            padding: 20px;
            border-radius: 5px;
            text-align: center;
            margin-top: 20px;
        }
        
        @media (max-width: 768px) {
            .form-row {
                flex-direction: column;
                gap: 0;
            }
            
            .package-option {
                flex: 1 0 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>体检预约系统</h1>
        </header>
        
        <div class="appointment-form">
            <form id="appointmentForm">
                <div class="form-row">
                    <div class="form-group">
                        <label for="name">姓名</label>
                        <input type="text" id="name" name="name" required>
                    </div>
                    <div class="form-group">
                        <label for="gender">性别</label>
                        <select id="gender" name="gender" required>
                            <option value="">请选择性别</option>
                            <option value="male">男</option>
                            <option value="female">女</option>
                        </select>
                    </div>
                </div>
                
                <div class="form-row">
                    <div class="form-group">
                        <label for="idCard">身份证号</label>
                        <input type="text" id="idCard" name="idCard" required>
                    </div>
                    <div class="form-group">
                        <label for="phone">手机号码</label>
                        <input type="tel" id="phone" name="phone" required>
                    </div>
                </div>
                
                <div class="form-row">
                    <div class="form-group">
                        <label for="birthDate">出生日期</label>
                        <input type="date" id="birthDate" name="birthDate" required>
                    </div>
                    <div class="form-group">
                        <label for="age">年龄</label>
                        <input type="text" id="age" name="age" readonly>
                    </div>
                </div>
                
                <div class="form-group">
                    <label for="appointmentDate">预约日期</label>
                    <input type="date" id="appointmentDate" name="appointmentDate" required>
                </div>
                
                <div class="form-group">
                    <label for="appointmentTime">预约时间段</label>
                    <select id="appointmentTime" name="appointmentTime" required>
                        <option value="">请选择时间段</option>
                        <option value="08:00-09:00">08:00-09:00</option>
                        <option value="09:00-10:00">09:00-10:00</option>
                        <option value="10:00-11:00">10:00-11:00</option>
                        <option value="13:00-14:00">13:00-14:00</option>
                        <option value="14:00-15:00">14:00-15:00</option>
                    </select>
                </div>
                
                <div class="form-group">
                    <label>体检套餐</label>
                    <div class="package-options">
                        <div class="package-option">
                            <div class="package-card" data-package="basic">
                                <h3>基础套餐</h3>
                                <div class="price">¥299</div>
                                <div class="description">
                                    包含血常规、尿常规、肝功能、肾功能、心电图等基础检查项目
                                </div>
                            </div>
                        </div>
                        <div class="package-option">
                            <div class="package-card" data-package="standard">
                                <h3>标准套餐</h3>
                                <div class="price">¥599</div>
                                <div class="description">
                                    包含基础套餐项目，增加血脂、血糖、B超(肝、胆、胰、脾)、胸透等检查
                                </div>
                            </div>
                        </div>
                        <div class="package-option">
                            <div class="package-card" data-package="premium">
                                <h3>尊享套餐</h3>
                                <div class="price">¥1299</div>
                                <div class="description">
                                    包含标准套餐项目，增加肿瘤标志物筛查、CT检查、胃镜检查等高级项目
                                </div>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" id="selectedPackage" name="selectedPackage" required>
                </div>
                
                <button type="submit" class="submit-btn">提交预约</button>
            </form>
            
            <div class="success-message" id="successMessage">
                <h2>预约成功!</h2>
                <p>您的体检预约已提交成功，我们已发送预约确认短信至您的手机。</p>
                <p>预约编号: <span id="appointmentNumber"></span></p>
                <p>请按时前往体检中心，如有疑问请联系客服。</p>
            </div>
        </div>
    </div>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 计算年龄
            document.getElementById('birthDate').addEventListener('change', function() {
                const birthDate = new Date(this.value);
                const today = new Date();
                let age = today.getFullYear() - birthDate.getFullYear();
                const monthDiff = today.getMonth() - birthDate.getMonth();
                
                if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
                    age--;
                }
                
                document.getElementById('age').value = age;
            });
            
            // 套餐选择
            const packageCards = document.querySelectorAll('.package-card');
            packageCards.forEach(card => {
                card.addEventListener('click', function() {
                    packageCards.forEach(c => c.classList.remove('selected'));
                    this.classList.add('selected');
                    document.getElementById('selectedPackage').value = this.getAttribute('data-package');
                });
            });
            
            // 表单提交
            document.getElementById('appointmentForm').addEventListener('submit', function(e) {
                e.preventDefault();
                
                // 这里应该是实际的表单验证和提交逻辑
                // 模拟成功提交
                const formData = new FormData(this);
                const appointmentData = {};
                formData.forEach((value, key) => {
                    appointmentData[key] = value;
                });
                
                console.log('预约数据:', appointmentData);
                
                // 生成随机预约编号
                const appointmentNumber = 'TJ' + Math.floor(Math.random() * 1000000).toString().padStart(6, '0');
                document.getElementById('appointmentNumber').textContent = appointmentNumber;
                
                // 显示成功消息
                document.getElementById('appointmentForm').style.display = 'none';
                document.getElementById('successMessage').style.display = 'block';
                
                // 在实际应用中，这里应该发送AJAX请求到服务器
                // fetch('/api/appointments', {
                //     method: 'POST',
                //     body: JSON.stringify(appointmentData),
                //     headers: {
                //         'Content-Type': 'application/json'
                //     }
                // })
                // .then(response => response.json())
                // .then(data => {
                //     // 处理响应
                // })
                // .catch(error => {
                //     console.error('Error:', error);
                // });
            });
            
            // 设置预约日期的最小值为今天
            const today = new Date();
            const dd = String(today.getDate()).padStart(2, '0');
            const mm = String(today.getMonth() + 1).padStart(2, '0');
            const yyyy = today.getFullYear();
            const minDate = yyyy + '-' + mm + '-' + dd;
            document.getElementById('appointmentDate').setAttribute('min', minDate);
        });
    </script>
</body>
</html>